<?php

class hook extends stthemehook {

    public function hookCustom() {
        //overide hook manage
//        $method = array($this, 'load_custom_wp_admin_scripts');
//        add_action('admin_enqueue_scripts', $method);
//        $method = array($this, 'customFieldCreate');
//        add_action('admin_menu', $method);
//        $method = array($this, 'customFieldHandle');
//        add_action('edit_post', $method);
    }

    public function customFieldCreate() {
        if (function_exists('add_meta_box')) {
            $controllerName = $this->config['theme_name'] . "Controller";
            $controllerObject = new $controllerName($this->config);
            $controllerObject->actionName = 'addPrice';
            $method = array($controllerObject, 'getAction');
            add_meta_box('custom_field', 'Produktpris', $method, 'page', 'normal');
        }
    }

    public function customFieldHandle() {
        if (isset($_POST['post_ID']))
            $pID = $_POST['post_ID'];
        if (isset($_POST['action']) && $_POST['action'] == 'editpost') {
//            if (isset($_POST['content_type'])) {
            $upload_data = wp_upload_dir();
            $img_data = array();
            foreach ($_POST['image_product'] as $row) {
                $img_data[] = $upload_data['url'] . '/' . basename($row);
            }

            $pdf_data = array();
            foreach ($_POST['pdf_product'] as $row) {
                if ($row != '')
                    $pdf_data[] = $upload_data['url'] . '/' . basename($row);
                else
                    $pdf_data[] = '';
            }

            update_post_meta($pID, 'the_text', serialize($_POST['the_text']));
            update_post_meta($pID, 'the_name', serialize($_POST['the_name']));
            update_post_meta($pID, 'the_link', serialize($_POST['the_link']));
            update_post_meta($pID, 'album_id', serialize($_POST['album_id']));
            update_post_meta($pID, 'image_product', $img_data);
            update_post_meta($pID, 'pdf_product', $pdf_data);
            update_post_meta($pID, 'content_type', serialize($_POST['content_type']));

//            }
        }
    }

    public function load_custom_wp_admin_scripts() {
//        wp_register_style('custom_wp_admin_css', get_bloginfo('template_directory') . '/admin-functions/css/admin-style.css', false, '1.0.0');
//        wp_enqueue_style('custom_wp_admin_css');

        wp_register_script('ajaxupload_admin_script', get_bloginfo('template_directory') . '/admin-functions/scripts/ajaxupload.js', false, '1.0.0');
        wp_enqueue_script('ajaxupload_admin_script');
//        wp_register_script('custom_wp_admin_script', get_bloginfo('template_directory') . '/admin-functions/scripts/admin-script.js', false, '1.0.0');
//        wp_enqueue_script('custom_wp_admin_script');
        wp_register_script('sttheme_admin_script', get_bloginfo('template_directory') . '/admin-functions/scripts/sttheme.js', false, '1.0.0');
        wp_enqueue_script('sttheme_admin_script');
    }

    function widgetsInit() {
        unregister_widget('WP_Widget_Archives');
        unregister_widget('WP_Widget_Calendar');
        unregister_widget('WP_Widget_Categories');
        unregister_widget('WP_Widget_Links');
        unregister_widget('WP_Widget_Meta');
        unregister_widget('WP_Widget_Pages');
        unregister_widget('WP_Widget_Recent_Comments');
        unregister_widget('WP_Widget_Recent_Posts');
        unregister_widget('WP_Widget_RSS');
        unregister_widget('WP_Widget_Search');
        unregister_widget('WP_Widget_Tag_Cloud');
        unregister_widget('WP_Widget_Text');
        unregister_widget('WP_Nav_Menu_Widget');
// 
        register_sidebar(array(
            'name' => __('Top Sidebar', $this->config['theme_name']),
            'id' => 'top_sidebar',
            'description' => __('Top Sidebar', $this->config['theme_name']),
            'before_widget' => '<div id="%1$s" class="widget-container %2$s">',
            'after_widget' => '</div>',
            'before_title' => '<h3 class="widget-title">',
            'after_title' => '</h3>',
        ));
    }

}

?>